package generic;


import generic.generator.Generator;
import generic.method.Generators;
import utils.Log;

import java.util.ArrayList;
import java.util.Random;

/**
 * 15.6 构建复杂模型
 */
class Product {
    final int id;
    String desc;
    double price;

    public Product(int id, String desc, double price) {
        this.id = id;
        this.desc = desc;
        this.price = price;
        Log.vn(toString());
    }

    @Override
    public String toString() {
        return "Produce{" +
                "id=" + id +
                ", desc='" + desc + '\'' +
                ", price=" + price +
                '}';
    }

    public void priceChange(double change) {
        price += change;
    }

    public static Generator<Product> generator() {
        return new Generator<Product>() {
            Random rand = new Random(47);
            @Override
            public Product next() {
                return new Product(rand.nextInt(1000), "Test ", Math.round(rand.nextDouble() * 1000.0) + 0.99 );
            }
        };
    }
}



class Shelf extends ArrayList<Product> {
    public Shelf(int n) {
        Generators.fill(this, Product.generator(), n);
    }

    static class Aisle extends ArrayList<Shelf> {
        public Aisle(int nS, int nP) {
            for (int i = 0; i < nS; i++) {
                add(new Shelf(nP));
            }
        }
    }
}

class CheckoutStand {}

class Office {}


public class Store extends ArrayList<Shelf.Aisle> {

    private ArrayList<CheckoutStand> checkouts = new ArrayList<>();
    private Office office = new Office();

    public Store(int nA, int nS, int nP) {
        for (int i = 0; i < nA; i++) {
            add(new Shelf.Aisle(nS, nP));
        }
    }


    @Override
    public String toString() {
        StringBuilder sb = new StringBuilder();
        for (Shelf.Aisle a : this) {
            for (Shelf s: a) {
                for (Product p : s){
                    sb.append(p);
                    sb.append("\n");
                }
            }
        }
        return sb.toString();
    }

    public static void main(String[] args) {
        Log.vn(new Store(14, 5, 10));
    }
}
